package avicit.bdp.dgs.qa.rest;

import avicit.bdp.dgs.qa.dto.SubscribeDTO;
import avicit.bdp.dgs.qa.service.SubscribeService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2023-03-30
 * @类说明：SubscribeRest
 * @修改记录：
 * @注意事项：
 * @主要功能：质量作业订阅Rest接口
 */
@RestController
@Api(tags = "qa", description = "质量作业订阅Rest接口")
@RequestMapping("/api/bdp/dgs/qa/subscribe")
public class SubscribeRest {
    @Autowired
    private SubscribeService subscribeService;

    /**
     * 新增订阅人
     * @param subscribeDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增订阅人")
    public ResponseMsg<Boolean> addSubscribe(@RequestBody SubscribeDTO subscribeDTO) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.subscribeService.addSubscribe(subscribeDTO));

        return responseMsg;
    }

    /**
     * 删除/批量删除订阅人，多个id使用英文逗号隔开
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除/批量删除订阅人，多个id使用英文逗号隔开")
    public ResponseMsg<Integer> deleteSubscribe(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.subscribeService.deleteSubscribe(id));

        return responseMsg;
    }

    /**
     * 修改订阅人
     * @param subscribeDTO
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改订阅人")
    public ResponseMsg<Boolean> updateSubscribe(@RequestBody SubscribeDTO subscribeDTO) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.subscribeService.updateSubscribe(subscribeDTO));

        return responseMsg;
    }

    /**
     * 查询订阅详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value = "查询订阅详情")
    public ResponseMsg<SubscribeDTO> getSubscribeDetail(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<SubscribeDTO> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.subscribeService.getSubscribeDetail(id));

        return responseMsg;
    }

    /**
     * 分页查询订阅信息
     * @param jobId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/query")
    @ApiOperation(value = "分页查询订阅信息")
    public ResponseMsg<QueryRespBean<SubscribeDTO>> querySubscribe(
            @ApiParam(value = "作业Id", name = "jobId") @RequestParam String jobId,
            @ApiParam(value = "当前页", name = "pageNo") @RequestParam(defaultValue = "1", required = false) Integer pageNo,
            @ApiParam(value = "每页大小", name = "pageSize") @RequestParam(defaultValue = "10", required = false) Integer pageSize) {
        ResponseMsg<QueryRespBean<SubscribeDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.subscribeService.querySubscribe(jobId, pageNo,pageSize));

        return responseMsg;
    }

    /**
     * 列举订阅信息
     * @param jobId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "列举订阅信息")
    public ResponseMsg<List<SubscribeDTO>> getSubscribeList(@ApiParam(value = "作业Id", name = "jobId") @RequestParam String jobId) {
        ResponseMsg<List<SubscribeDTO>> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.subscribeService.getSubscribeList(jobId));

        return responseMsg;
    }

    /**
     * 检查订阅人是否重复订阅
     * @param jobId
     * @param userId
     * @param type
     * @return
     */
    @GetMapping("/check")
    @ApiOperation(value = "判读订阅信息是否重复")
    public ResponseMsg<Boolean> checkValid(@ApiParam(value = "质量作业ID", name = "jobId") @RequestParam String jobId,
                                           @ApiParam(value = "用户ID", name = "userId") @RequestParam String userId,
                                           @ApiParam(value = "订阅方式", name = "type") @RequestParam Integer type) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();

        responseMsg.setResponseBody(this.subscribeService.checkValid(jobId, userId, type));

        return responseMsg;
    }
}
